


#ifndef CardPort_h__
#define CardPort_h__

#include <stdint.h>
#include <Card.h>

typedef enum PortTypeEnum{
	PT_PICC,
}PortType;

enum {
	Port_Cfg_Rf,
};


enum {
	Port_Index_PICC,
	Port_Index_ICC,
	Port_Index_SAM1,
	Port_Index_SAM2,
	Port_Index_Max
};

typedef struct CardPortStruct CardPort;

void CardPort_Register(CardPort * port, int index);
int CardPort_Picc_SetRf(uint8_t index, uint8_t state);
int CardPort_Picc_Detect(uint8_t index, uint8_t type);
int CardPort_Picc_Activate(uint8_t index, uint8_t type, uint8_t req, void * info);
int CardPort_Picc_Destroy(uint8_t index, uint8_t num);
int CardPort_Picc_Deactivate(uint8_t index, uint8_t num);
int CardPort_Picc_Setup(uint8_t index, uint8_t num, uint8_t type, void* param, uint8_t ats[]);
int CardPort_Picc_Teardown(uint8_t index, uint8_t num);
int CardPort_Picc_Exchange(uint8_t index, uint8_t num, uint8_t capdu[], unsigned int clen, uint8_t rapdu[], unsigned int * rlen);
int CardPort_Picc_Check(uint8_t index, uint8_t num);

int CardPort_PMem_Setup(uint8_t index, uint8_t num, uint8_t type, void* param);
int CardPort_PMem_Authen(uint8_t index, uint8_t num, void* param, uint8_t* key, uint8_t klen);

#define Port_Picc_SetRf(state)	CardPort_Picc_SetRf(Port_Index_PICC, state)
#define Port_Picc_Detect(type)	CardPort_Picc_Detect(Port_Index_PICC, type)

#define Port_Picc_Destroy()		CardPort_Picc_Destroy(Port_Index_PICC, 0)
#define Port_Picc_Teardown()	CardPort_Picc_Teardown(Port_Index_PICC, 0)
#define Port_Picc_Deactivate()	CardPort_Picc_Deactivate(Port_Index_PICC, 0)
#define Port_Picc_Activate(type, req, info)		CardPort_Picc_Activate(Port_Index_PICC, type, req, info)
#define Port_Picc_Setup(type, param, resp)		CardPort_Picc_Setup(Port_Index_PICC, 0, type, param, resp)
#define Port_Picc_Exchange(capdu, clen, rapdu, prlen)	CardPort_Picc_Exchange(Port_Index_PICC, 0, capdu, clen, rapdu, prlen)
#define Port_Picc_Check()		CardPort_Picc_Check(Port_Index_PICC, 0)

#define Port_Picc_Mem_Setup(type, param)	CardPort_PMem_Setup(Port_Index_PICC, 0, type, param)
#define Port_Picc_Mem_Authen(param, key, klen)	CardPort_PMem_Authen(Port_Index_PICC, 0, param, key, klen)
#define Port_Picc_Mem_Read(address, buf, len)	CardPort_PMem_Read(Port_Index_PICC, 0, address, buf, len)
#define Port_Picc_Mem_Write(address, buf, len)	CardPort_PMem_Write(Port_Index_PICC, 0, address, buf, len)
#define Port_Picc_Mem_Control(op, param, cbuf, clen, rbuf, rlen)	\
				CardPort_PMem_Control(Port_Index_PICC, 0, op, param, cbuf, clen, rbuf, rlen)
#endif // CardPort_h__
